package com.neuedu.ylbx.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.neuedu.ylbx.pojo.DiseaseInfo;
import com.neuedu.ylbx.pojo.InpatientDisease;
import com.neuedu.ylbx.pojo.PatientRegistration;
import com.neuedu.ylbx.service.DiseaseInfoService;
import com.neuedu.ylbx.service.InpatientDiagnosisService;
import com.neuedu.ylbx.service.InpatientDiseaseService;
import com.neuedu.ylbx.service.PatientRegistrationService;
import com.neuedu.ylbx.utils.ResultVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @version V1.0
 * @author: xianzhen
 * @date: 2025/7/9
 */

@RestController
@RequestMapping("/inpatientDisease")
@Tag(name = "住院疾病控制器")
@CrossOrigin
public class InpatientDiseaseController {
    @Autowired
    InpatientDiseaseService inpatientDiseaseService;

    @Autowired
    DiseaseInfoService diseaseInfoService;
//    @Autowired
//    PatientRegistrationService patientRegistrationService;
//    @Autowired
//    DiseaseInfoService diseaseInfoService;

    @GetMapping("/diseases")
    @Operation(summary = "获取疾病列表")
    public ResultVo<List<DiseaseInfo>> listDiseaseInfo() throws  Exception{
//        return  ResultVo.ok(DiseaseInfoService.list( null, null));
        return ResultVo.ok(diseaseInfoService.list());
    }

    @PostMapping("/addDiagnosis")
    @Operation(summary = "添加诊断")
//    public ResultVo addDiagnosis(String patientId, String diseaseId, String diagnosisTime, String diagnosisResult) throws Exception{
//        InpatientDiseaseService.save(patientId, diseaseId, diagnosisTime, diagnosisResult);
//        return ResultVo.ok(inpatientDiseaseService.addDiagnosis(patientId, diseaseId, diagnosisTime, diagnosisResult));
//    }

    public ResultVo addDiagnosis(InpatientDisease id) throws Exception{
        inpatientDiseaseService.save(id);
        return ResultVo.ok("添加成功");
    }

    @PostMapping("/queryDiagnosis")
    @Operation(summary = "查询患者疾病")
//    public ResultVo queryDiagnosis(String patientId, String diseaseId) throws Exception{
//        return ResultVo.ok(inpatientDiseaseService.queryDiagnosis(patientId, diseaseId));
//    }
    public ResultVo<DiseaseInfo> queryDiagnosis (Integer patientId) throws Exception {
        InpatientDisease ipd;
        Integer di;
        //查询患者诊断信息
        if (patientId != null) {
            ipd = inpatientDiseaseService.getById(patientId);
        } else {
            return ResultVo.fail("患者不存在");
        }
        //获取疾病id
        if (ipd != null) {
            di = ipd.getDiseaseId();
        }
        else {
            return ResultVo.fail("疾病不存在");
        }
        //获取疾病信息
        DiseaseInfo din = diseaseInfoService.getById(di);
        //返回疾病信息
        return ResultVo.ok(din);
    }
}
